
Partial Class LoginE
    Inherits System.Web.UI.Page

    Private Const Q As String = Chr(34)

    Private moServer As SQLAutoDocLib.Server = Nothing
    Private moDatabase As SQLAutoDocLib.Database = Nothing

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sSID As String
        Dim sDID As String
        Dim sIsFramed As String = ""

        If IsPostBack = False Then
            sSID = Request.QueryString("S")
            sDID = Request.QueryString("D")
            sIsFramed = Request.QueryString("F")

            hidSID.Value = sSID
            hidDID.Value = sDID
            hidF.Value = sIsFramed

            ARefresh.HRef = "SQLoginE.aspx?S=" & sSID & "&D=" & sDID
        Else
            sSID = hidSID.Value
            sDID = hidDID.Value
            sIsFramed = hidF.Value
        End If

        moServer = New SQLAutoDocLib.Server(sSID)
        moServer.Load()

        moDatabase = New SQLAutoDocLib.Database(sDID)
        moDatabase.Load()

        If IsPostBack = True _
                AndAlso hidToolbarAction.Value = "save" Then

            Dim sFieldIDs() As String = Request.Form("FID").Split(",")
            For Each sID As String In sFieldIDs
                If IsNumeric(sID) Then
                    Dim sFDesc As String = Request.Form("desc:" & sID)
                    If sFDesc > "" Then
                        Dim oLogin As New SQLAutoDocLib.Login(sID)
                        oLogin.Load()
                        oLogin.Desc = sFDesc
                        oLogin.Save()
                    End If
                End If
            Next
        End If
    End Sub

    Protected Sub ShowLoginList()
        HttpContext.Current.Response.Write("<table class=" & Q & "wmObjectList_T" & Q & " style=" & Q & "background-color: #C3C4C1; border-bottom: solid 1px black;" & Q & ">")

        HttpContext.Current.Response.Write("<tr class=" & Q & "wmObjectList_TH" & Q & " style=" & Q & "height: 39px; background-color: #C3C4C1; border-bottom: solid 1px black;" & Q & ">")
        HttpContext.Current.Response.Write("<td class=" & Q & "wmLoginList_ZM" & Q & _
                                              " style=" & Q & "height: 25px;" & Q & ">")
        HttpContext.Current.Response.Write("Modified")
        HttpContext.Current.Response.Write("</td>")

        HttpContext.Current.Response.Write("<td class=" & Q & "wmLoginList_ZN" & Q & ">")
        HttpContext.Current.Response.Write("Name")
        HttpContext.Current.Response.Write("</td>")

        HttpContext.Current.Response.Write("</tr>")

        Dim oList As New ArrayList

        Dim bAlternatingRow As Boolean = False

        Dim oFactory As New SQLAutoDocLib.Login_Factory
        For Each oLogin As SQLAutoDocLib.Login In oFactory.GetAllLoginsForDatabase(moDatabase.ID)
            If bAlternatingRow = False Then
                HttpContext.Current.Response.Write("<tr class=" & Q & "wmObjectList_T" & Q & ">")
            Else
                HttpContext.Current.Response.Write("<tr class=" & Q & "wmObjectList_TA" & Q & ">")
            End If

            HttpContext.Current.Response.Write("<td>")
            HttpContext.Current.Response.Write(oLogin.LastModified)
            HttpContext.Current.Response.Write("</td>")

            HttpContext.Current.Response.Write("<td>")
            HttpContext.Current.Response.Write(oLogin.Login)
            HttpContext.Current.Response.Write("</td>")

            HttpContext.Current.Response.Write("</tr>")

            If Not IsNumeric(hidF.Value) _
                    OrElse oLogin.Desc > "" Then

                If bAlternatingRow = False Then
                    HttpContext.Current.Response.Write("<tr class=" & Q & "wmObjectList_T" & Q & ">")
                Else
                    HttpContext.Current.Response.Write("<tr class=" & Q & "wmObjectList_TA" & Q & ">")
                End If
                Response.Write("<td>&nbsp;</td>")
                Response.Write("<td colspan=" & Q & 3 & Q & ">")

                If Not IsNumeric(hidF.Value) Then
                    Response.Write("<input type=" & Q & "hidden" & Q & _
                                         " name=" & Q & "fid" & Q & _
                                         " value=" & Q & oLogin.ID & Q & "/>")

                    Response.Write("<input type=" & Q & "text" & Q & _
                                         " name=" & Q & "desc:" & oLogin.ID & Q & _
                                         " value=" & Q & oLogin.Desc & Q & _
                                         " style=" & Q & "margin-left: 10px; width: 350px;" & Q & "/>")
                Else
                    Response.Write("<span class=" & Q & "wmObjectDetail_Desc" & Q & ">Desc: </span>")
                    Response.Write(oLogin.Desc)
                End If

                Response.Write("</td>")
                Response.Write("</tr>")
            End If
        Next

        HttpContext.Current.Response.Write("</table>")
    End Sub

    Protected Function FormLabel() As String
        Dim oFactory As New SQLAutoDocLib.ScanHistory_Factory
        Dim sCurrentScan As String = ""
        Dim sLastScan As String = ""
        oFactory.GetTimeOfLastScan(moDatabase.ID, SQLAutoDocLib.ScanSchedule.Type.SchemaScan, "SQLAutoDocLib.Login", sCurrentScan, sLastScan)

        Dim sValue As String = "View Login List for " & moDatabase.Name & " last scan completed " & sLastScan

        If sCurrentScan > "" Then
            sValue = " scan in progress started " & sCurrentScan
        End If

        Return sValue
    End Function

    Protected Function ScanMode() As String
        Return "Logins"
    End Function

    Protected Function EditMode() As String
        Return "Login"
    End Function

    Protected Function ServerID() As String
        Return moServer.ID
    End Function

    Protected Function DatabaseID() As String
        Return moDatabase.ID
    End Function
End Class
